import '../helper/dioHelper2.dart';

class Calculate {
  int ID;
  String Guid;
  String DoTM;
  String TM;
  double P;
  double R;
  double FDL;
  double QP;
  double QF;
  double QZ;
  double H;
  double Money;
  String Remarks;

  Calculate(this.ID, this.Guid, this.DoTM, this.TM, this.P, this.R, this.FDL,
      this.QP, this.QF, this.QZ, this.H, this.Money, this.Remarks);
  Calculate.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        Guid = json["Guid"],
        DoTM = json["DoTM"],
        TM = json["TM"],
        P = json["P"] * 1.0,
        R = json["R"] * 1.0,
        FDL = json["FDL"] * 1.0,
        QP = json["QP"] * 1.0,
        QF = json["QF"] * 1.0,
        QZ = json["QZ"] * 1.0,
        H = json["H"] * 1.0,
        Money = json["Money"] * 1.0,
        Remarks = json["Remarks"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'Guid': Guid,
        'DoTM': DoTM,
        'TM': TM,
        'P': P,
        'R': R,
        'FDL': FDL,
        'QP': QP,
        'QF': QF,
        'QZ': QZ,
        'H': H,
        'Money': Money,
        'Remarks': Remarks,
      };
  static Future<bool> Add(Calculate x1) async {
    var response = await DioHelper.Post("/Calculate/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(Calculate x1) async {
    var response = await DioHelper.Post("/Calculate/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(Calculate x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/Calculate/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<Calculate?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/Calculate/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200)
      return  Calculate.fromJson(response.data);
    return null;
  }

    static  Future<List<Calculate>> GetNew() async {
    var response = await DioHelper.Get("/DP/GetNewCalculate", null);

  var list1 =  <Calculate>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new Calculate.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<Calculate>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/Calculate/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <Calculate>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new Calculate.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<Calculate>> GetAllList() async {
    var response = await DioHelper.Get("/Calculate/GetAllList", {});
    var list1 =  <Calculate>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new Calculate.fromJson(x));
      }
    }
    return list1;
  }
}
